﻿using System.Web.Mvc;
using Web7.Mvc.ActionInvokers;
using Web7.Mvc.ViewEngines;

namespace Web7.Core.ActionFilters.Result
{
    public class ViewResultFilter : FilterProvider, IResultFilter
    {
        private IAwareViewEngine _awareViewEngine;

        public ViewResultFilter(IAwareViewEngine awareViewEngine)
        {
            _awareViewEngine = awareViewEngine;
        }

        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            var viewResultBase = filterContext.Result as ViewResultBase;

            if (viewResultBase == null)
            {
                return;
            }

            viewResultBase.ViewEngineCollection = new ViewEngineCollection(new[] { _awareViewEngine });
        }

        public void OnResultExecuted(ResultExecutedContext filterContext)
        {

        }
    }
}
